﻿using HBase;
 
using Oracle.DataAccess.Client;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.IO;

namespace hCommand {
    public class DBUtils {


   
        private static IDbConnection wMSConnection = null;
        public static IDbConnection wMSConn(GKDBType type) {
            if( wMSConnection != null ) {
                return wMSConnection;
            }
            wMSConnection = newWMSConn(type);
            return wMSConnection;
        }
        private static IDbConnection readConnection = null;
        public static IDbConnection wCSConn(GKDBType type) {
            if(readConnection != null ) {
                return readConnection;
            }
            readConnection = createConnection(type, "DB_READ");
            return readConnection;
        }
        public static IDbConnection newWMSConn(GKDBType type) {
            IDbConnection conn= createConnection(type, "DB_OPER");
            return conn;
        }
     
        public static IDbConnection createConnection(GKDBType type,string name) {
            string connStr = ConfUtil. getStr( name);
            if ( type == GKDBType.sqlserver ) {

                DbProviderFactories.RegisterFactory("System.Data.SqlClient", System.Data.SqlClient.SqlClientFactory.Instance);
                IDbConnection connection = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateConnection();
                connection.ConnectionString = connStr;
                connection.Open();
                return connection;
            }
            if( type == GKDBType.oracle ) {
                var connection = new OracleConnection(connStr);
                connection.Open();
                return connection;
            }

            if( type == GKDBType.mySql ) {
                var connection = new MySql.Data.MySqlClient.MySqlConnection(connStr);
                connection.Open();
                return connection;
            }
            return null;
        }
       
         

        
    }
}
